home *** CD-ROM | disk | FTP | other *** search
/ MacTech 1 to 12 / MacTech-vol-1-12.toast / Source / MacTech® Magazine / Volume 11 - 1995 / 11.04 Apr 95 / TreeAppƒ / TreeWindowƒ / CPPTreeWindow.cp next >
Encoding:
Text File  |  1996-04-04  |  5.6 KB  |  213 lines  |  [TEXT/KAHL]

  1. /***************************************************** IMPLEMENTATION
  2.     DATE:    10/19/93
  3.  
  4.     CLASS:  CPPTreeWindow
  5.     
  6.     SUPERCLASS: CPPScrollWindow
  7.     
  8.         This C++ class manages a window which has a visual tree
  9.     
  10. ********************************************************************/
  11.  
  12. #include "CPPTreeWindow.h"
  13. #include <Commands.h>
  14. #include <MathTools.h>
  15. #include <CPPDRequest.h>
  16. #include "MyCommands.h"
  17. #include "CPPString.h"
  18. #include <CPPTreeArea.h>
  19. #include <CPPVisualTree.h>
  20. #include <CPPVisualTreeNode.h>
  21.  
  22. /*-----------------------------------------------------------------*/
  23. /*------------------------ PUBLIC METHODS -------------------------*/
  24. /*-----------------------------------------------------------------*/
  25.  
  26.     CPPTreeWindow::CPPTreeWindow (CPPWindowManager *theManager, int ResID) :
  27.                 CPPWindow (theManager, ResID, FALSE, TRUE, geneva, 9)
  28.     {    
  29.         Point    topLeft;
  30.         
  31.         theTreeArea = new CPPTreeArea(this, TRUE, TRUE, 10, 10, 
  32.                                         kTopDown, kJustCenter, kRightAngle, 25);        
  33.         
  34.         SetMinMaxSize(70, 70, kPageWidth + kSBarWidth,
  35.                          kPageHeight + kSBarWidth);
  36.     }
  37.                          
  38. /*-----------------------------------------------------------------*/
  39.  
  40.     CPPTreeWindow::~CPPTreeWindow (void)
  41.     {
  42.         delete theTreeArea;
  43.     }
  44.  
  45. /*-----------------------------------------------------------------*/
  46.  
  47.     Boolean    CPPTreeWindow::Member (char *className)
  48.     {
  49.         if (strcmp(className, CPPTreeWindow::ClassName()) == 0)
  50.           return TRUE;
  51.         else
  52.           return CPPWindow::Member(className);
  53.     }
  54.  
  55. /*-----------------------------------------------------------------*/
  56.  
  57.     char    *CPPTreeWindow::ClassName (void)
  58.     {
  59.         return "CPPTreeWindow";
  60.     }
  61.  
  62. /*-----------------------------------------------------------------*/
  63.  
  64.     Boolean    CPPTreeWindow::DoCommand (short commandID)
  65.     /* the default method sends the command to the target of the */
  66.     /* window. */
  67.     /* SUBCLASS SHOULD OVERRIDE */
  68.     {
  69.         StringPtr    Reply = NULL;
  70.         long        TLint = 0;
  71.         CPPVisualTreeNode    *OperateOn = NULL,
  72.                             *TempNode = NULL;
  73.         CPPString    *STemp = NULL;
  74.         Boolean        result = TRUE;
  75.                 
  76.         switch (commandID) {
  77.         
  78. // kTreeMenu
  79.             case kCmdLength        :
  80.                 if (DoRequest ("\pEnter the new branch length", "\p25", &Reply))
  81.                   {
  82.                       StringToNum (Reply, &TLint);
  83.                       this->theTreeArea->SetBranchLength ((short)TLint);
  84.                   }
  85.                 break;
  86.                 
  87.             case kCmdAdd        :
  88.                 if (this->theTreeArea->lastClicked)
  89.                   {
  90.                     OperateOn = (CPPVisualTreeNode *)this->theTreeArea->lastClicked;
  91.                     if (DoRequest ("\pEnter Child's name", "\pChild", &Reply))
  92.                       {
  93.                           STemp = new CPPString (Reply, TRUE);
  94.                           TempNode = new CPPVisualTreeNode (STemp, (CPPTree *)this->theTreeArea, 
  95.                                                           TRUE, FALSE);
  96.                         OperateOn->AddNode (TempNode);
  97.                       }
  98.                   }
  99.                 break;
  100.             
  101.             case kCmdChangeNode        :
  102.                 if (this->theTreeArea->lastClicked)
  103.                   {
  104.                     OperateOn = (CPPVisualTreeNode *)this->theTreeArea->lastClicked;
  105.                     if (DoRequest ("\pEnter new name", "\pChild", &Reply))
  106.                       {
  107.                           STemp = new CPPString (Reply, TRUE);
  108.                         OperateOn->SetNodeData (STemp, TRUE);
  109.                       }
  110.                   }
  111.                 break;
  112.             
  113.             case kCmdInsert        :
  114.                 if (this->theTreeArea->lastClicked)
  115.                   {
  116.                     OperateOn = (CPPVisualTreeNode *)this->theTreeArea->lastClicked;
  117.                     if (DoRequest ("\pEnter new Parent's name", "\pParent", &Reply))
  118.                       {
  119.                           STemp = new CPPString (Reply, TRUE);
  120.                           TempNode = new CPPVisualTreeNode (STemp, (CPPTree *)this->theTreeArea, 
  121.                                                           TRUE, FALSE);
  122.                         OperateOn->InsertParent (TempNode);
  123.                       }
  124.                   }
  125.                 break;
  126.             
  127.             case kCmdDeleteNode        :
  128.                 ((CPPVisualTree *)this->theTreeArea)->DoClear();
  129.                 break;
  130.                 
  131.             case kCmdDeleteFamily        :
  132.                 if (this->theTreeArea->lastClicked)
  133.                   {
  134.                     OperateOn = (CPPVisualTreeNode *)this->theTreeArea->lastClicked;
  135.                     OperateOn->DeleteFamily (OperateOn);
  136.                   }
  137.                 break;
  138.                                 
  139. // kOrientMenu
  140.             case kCmdTopDown    :
  141.                 this->theTreeArea->SetOrientation (kTopDown);
  142.                 break;
  143.                 
  144.             case kCmdBottomUp    :
  145.                 this->theTreeArea->SetOrientation (kBottomUp);
  146.                 break;
  147.                 
  148.             case kCmdLeft2Right :
  149.                 this->theTreeArea->SetOrientation (kLeft2Right);
  150.                 break;
  151.                 
  152.             case kCmdRight2Left :
  153.                 this->theTreeArea->SetOrientation (kRight2Left);
  154.                 break;
  155.                 
  156. // kJustMenu
  157.             case kCmdRightJust    :
  158.                 this->theTreeArea->SetJustification (kJustRight);
  159.                 break;
  160.                 
  161.             case kCmdLeftJust    :
  162.                 this->theTreeArea->SetJustification (kJustLeft);
  163.                 break;
  164.                 
  165.             case kCmdCenterJust :
  166.                 this->theTreeArea->SetJustification (kJustCenter);
  167.                 break;        
  168.  
  169. // kJoinMenu
  170.             case kCmdJoinNone    :
  171.                 this->theTreeArea->SetJoinType (kNoJoin);
  172.                 break;
  173.                 
  174.             case kCmdJoinAngle    :
  175.                 this->theTreeArea->SetJoinType (kRightAngle);
  176.                 break;
  177.                 
  178.             case kCmdJoinPoint    :        
  179.                 this->theTreeArea->SetJoinType (kPointToPoint);
  180.                 break;
  181.  
  182.             case kCmdCopy :
  183.                 return this->theTreeArea->DoCommand(commandID);
  184.                 break;
  185.                 
  186.             default :
  187.                 return CPPWindow::DoCommand(commandID);
  188.                 break;    
  189.         }
  190.         
  191.         return result;
  192.     }
  193.  
  194. /*-----------------------------------------------------------------*/
  195. /*---------------------- PROTECTED METHODS ------------------------*/
  196. /*-----------------------------------------------------------------*/
  197.  
  198.     void    CPPTreeWindow::DoUserChangeSize (short newWidth, short newHeight)
  199.     /* instance specific handler for resizing the window; use this */
  200.     /* opportunity to change the size of the scrollbars and TE area */
  201.     {
  202.         ((CPPScrollArea *)this->theTreeArea)->Resize (newWidth, newHeight);
  203.     }
  204.  
  205. /*-----------------------------------------------------------------*/
  206.  
  207.     void    CPPTreeWindow::DoUserUpdate (void)
  208.     /* instance specific handler for drawing the window's contents */
  209.     /* SUBCLASS SHOULD OVERRIDE */
  210.     {
  211.         this->theTreeArea->Draw();
  212.     }
  213.